//arg: url,img,loading,divtext,func;
function ajaxLoader()
{
    this.http = null;
    this.err  = null;
    this.posthas=new Array;
    
    this.init = function(arg)
    {
        try {
            this.http = new XMLHttpRequest()
        }
        catch (e)
        {
            try {
                this.http = new ActiveXObject("Msxml2.XMLHTTP")
            }
            catch (e) {
                this.http = new ActiveXObject("Microsoft.XMLHTTP");
            }
        }
        if (this.http == null) {
            alert("Browser does not support HTTP Request");
            this.err=1;
        }
        this.http.arg=arg;
    };
    this.addPost    = function(name,vl)
    {
        this.posthas[name]=vl;
    };
    this.onchange   = function()
    {
        if (this.readyState == 1)
        {
            try
            {
				if(this.arg.img==undefined)
                {
                    this.arg.img="ajaxldf";   
                }
                this.ld=document.createElement("span");
                this.ld.innerHTML='<span class="img"></span>';
                this.ld.className=this.arg.img;
                this.dld=document.getElementById(this.arg.loading);
                this.dld.insertBefore(this.ld,this.dld.firstChild);
            }
            catch (e) {}
        }
        if (this.readyState == 4)
        {
            try
            {
                this.dld.removeChild(this.ld);
            }
            catch (e) {}
            if(this.status != 200)
            {
                alert("There was a problem with the request.");
                return;
            }
            var datares = this.responseText;  
            this.sending=false;          
            if(this.arg.debug==true)
            {
            	alert(datares);
            }
            try {
                document.getElementById(this.arg.loading).innerHTML = ''
            }
            catch (e) {}
            try{
				eval("objson="+datares);	
				if(objson.act=="Redirect")
				{
					location=objson.url;
					return;
				}		
				document.getElementById(this.arg.divtext).innerHTML = objson.msg;		
			}catch(e){}            
            try {
            	if(typeof(objson)=="object")
				{
					objson.f=this.arg.f;
					this.arg.func(objson);
					return;
				}	
                
                this.arg.func(datares);
            }
            catch (e) {}
            try {
                document.getElementById(this.arg.divtext).innerHTML = datares;
            }
            catch (e) {}
            try
            {
                arrscr = (datares).split("<script>");
                arrscr = (arrscr[1]).split("</script>");
                eval(arrscr[0])
            }
            catch (e) {}
        }
    };
    this.send = function(post)
    {
        if(this.http.sending==true)return;
        this.http.sending=true;
        if (post == undefined) {
            this.http.open("GET", this.http.arg.url, true);
            post="";
        }
        else
        {
            this.http.open("POST", this.http.arg.url, true);
            this.http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            post+="&ajax=true&";            
            for(i in this.posthas)
            {
                post+='&'+i+'='+this.posthas[i];
            }
        }
        this.http.onreadystatechange = this.onchange;
        this.http.send(post);
    };    
}